//
// Created by 11510 on 2024/6/21.
//
#include <iostream>
#include <string>

using namespace std;

template<class T>
class RAII {
public:
    RAII(T *data) : _data(data) {}

    ~RAII() {
        if(_data){
            delete _data;
            _data = nullptr;
        }
    }

    T* operator->(){
        return _data;
    }

    T& operator*(){
        return *_data;
    }

    T* get()const{
        return _data;
    }

    void set(T* data){
        if(_data){
            delete _data;
            _data = nullptr;
        }
        _data = data;
    }


    RAII(const RAII&) = delete;
    RAII& operator=(const RAII&) = delete;
private:
    T *_data;
};

void test0() {
    RAII<int> raii(new int(12888));

    cout << *raii.get() << endl;
    cout << raii.get() << endl;
}

int main() {
    test0();
    return 0;
}